<?php
namespace app\modules\merchant\controllers;

use app\common\controllers\AccessController;
use app\modules\merchant\services\ConfigService;
use yii\base\UserException;

class ConfigController extends AccessController{

    //公告
    public function actionAnnounce(){
        if(ConfigService::announce(\Yii::$app->getRequest()->post("content"))){
            return "";
        }else{
            throw new UserException(ConfigService::getError());
        }
    }

    //显示
    public function actionShow(){
        if(ConfigService::show()){
            return "";
        }else{
            throw new UserException(ConfigService::getError());
        }
    }

    //自动接单
    public function actionAutoAccept(){
        if(ConfigService::autoAccept()){
            return "";
        }else{
            throw new UserException(ConfigService::getError());
        }
    }

    //配送方式
    public function actionDelivery(){
        if(ConfigService::delivery()){
            return "";
        }else{
            throw new UserException(ConfigService::getError());
        }
    }

    //配送规则
    public function actionDeliveryRule(){
        if(ConfigService::deliveryRule(\Yii::$app->getRequest()->post('rule'))){
            return "";
        }else{
            throw new UserException(ConfigService::getError());
        }
    }

    //营业时间
    public function actionBusinessTime($time){
        if(ConfigService::businessTime($time)){
            return "";
        }else{
            throw new UserException(ConfigService::getError());
        }
    }
}